package com.yequan.hbb.view.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yequan.hbb.R;
import com.yequan.hbb.adapter.QuesFragmentAdapter;
import com.yequan.hbb.app.MyApplication;
import com.yequan.hbb.view.fragment.lhp.SearchFragment;


/**
 * A simple {@link Fragment} subclass.
 */
public class QuestionFragment extends Fragment implements View.OnClickListener {


    private TabLayout tab;
    private ViewPager pager;
    private FragmentTransaction transaction;
    private Fragment lastFragment;
    public QuestionFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_question, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

        tab = (TabLayout) view.findViewById(R.id.question_tab);
        pager = ((ViewPager) view.findViewById(R.id.question_pager));
        view.findViewById(R.id.question_search).setOnClickListener(this);
        QuesFragmentAdapter adapter = new QuesFragmentAdapter(getChildFragmentManager(), view.getContext());
        pager.setAdapter(adapter);
        tab.setupWithViewPager(pager);
        lastFragment = this;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.question_search:
                SearchFragment instance = SearchFragment.getInstance(null,-1);
                FragmentTransaction transaction = ((AppCompatActivity) v.getContext())
                        .getSupportFragmentManager()
                        .beginTransaction()
                        .addToBackStack("SEARCH")
                        // .setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
                        .setCustomAnimations(R.anim.fragment_in,R.anim.fragment_out);
                transaction.replace(R.id.activity_main,instance).commit();
                MyApplication.main.findViewById(R.id.main_rg).setVisibility(View.GONE);
                MyApplication.main.findViewById(R.id.rl).setVisibility(View.GONE);
                break;
        }

    }

}
